/*
 * Copyright 2016 drakeet. https://github.com/drakeet
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.epfresh.adapter;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.epfresh.R;
import com.epfresh.activity.LoginActivity;
import com.epfresh.api.universalimageloader.core.ImageLoader;
import com.epfresh.api.utils.FileUtil;
import com.epfresh.api.utils.T;
import com.epfresh.bean.HomeCommTag;
import com.epfresh.bean.HomeGoodsOften;
import com.epfresh.bean.OfferMyList;
import com.epfresh.fragment.HomeFragmentNew;
import com.epfresh.fragment.TopFragmentRecycler;
import com.epfresh.global.BaseFragment;
import com.epfresh.views.tag.TagCloudView;
import com.epfresh.wxapi.pay.weipay.Util;

import java.util.ArrayList;

import multitype.ItemViewBinder;
import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;

public class ViewBinderHomeOftenOffer
        extends ItemViewBinder<HomeGoodsOften.ContentBean, ViewBinderHomeOftenOffer.ViewHolder> implements View.OnClickListener {//},RadioGroup.OnCheckedChangeListener {
    Resources resources;
    Drawable drawableSelect;
    Drawable drawableUnSelect;

    //    public TopFragmentRecycler context;
    public BaseFragment context;

    OnCartAddListener onCartAddListener;
    HomeGoodsOften.ContentBean bean;
/*

    FreshItemListener freshItemListener;

    public interface FreshItemListener {
        void freshItem(int type, int position, HomeGoodsOften.ContentBean goods, View v);
    }

    public FreshItemListener getFreshItemListener() {
        return freshItemListener;
    }

    public void setFreshItemListener(FreshItemListener freshItemListener) {
        this.freshItemListener = freshItemListener;
    }
*/

    boolean dcFlag = true;

    public boolean isDcFlag() {
        return dcFlag;
    }

    public void setDcFlag(boolean dcFlag) {
        this.dcFlag = dcFlag;
    }

    //红 黑 灰 绿
    int colors[] = {Color.RED, Color.parseColor("#434343"), Color.parseColor("#999999"), Color.parseColor("#24af75")};//价格激活红色，失活黑色横线

    public OnCartAddListener getOnCartAddListener() {
        return onCartAddListener;
    }

    public void setOnCartAddListener(OnCartAddListener onCartAddListener) {
        this.onCartAddListener = onCartAddListener;
    }

    public interface OnCartAddListener {
        void onCartAdd(int type, int position, HomeGoodsOften.ContentBean goods, View v);
    }

    @Override
    public void onClick(View v) {
        Object o = v.getTag(R.id.item_key_position);

        if (o != null && o instanceof Integer) {
            int position = (int) o;

            if (v.getTag(R.id.item_key_status) instanceof ArrayList) {
                ArrayList<HomeGoodsOften.ContentBean> list = (ArrayList<HomeGoodsOften.ContentBean>) v.getTag(R.id.item_key_status);
                for (int i = 0; i < list.size(); i++) {
                    list.get(i).setSelect(false);
                }
                if (v.getId() == R.id.rb_1) {
                    list.get(0).setSelect(true);
                } else if (v.getId() == R.id.rb_2) {
                    list.get(1).setSelect(true);
                } else if (v.getId() == R.id.rb_3) {
                    list.get(2).setSelect(true);
                }
                getAdapter().notifyItemChanged(position);
            }
            Log.e("adapter", "" + v.getTag(R.id.item_key_status).toString());
            if (v.getTag(R.id.item_key_status) instanceof HomeGoodsOften.ContentBean)
                bean = (HomeGoodsOften.ContentBean) v.getTag(R.id.item_key_status);
            else
                return;
            if (v.getId() == R.id.ed_price) {//购物车手动输入
                onCartAddListener.onCartAdd(1, position, bean, v);
            } else if (v.getId() == R.id.iv_add_count) {//添加
                if (bean.isAcceptOrders())
                    onCartAddListener.onCartAdd(2, position, bean, v);
                else
                    T.toast("暂不接单");
            } else if (v.getId() == R.id.iv_remove_count) {//减少
                onCartAddListener.onCartAdd(3, position, bean, v);

            } else if (v.getId() == R.id.tv_product_title || v.getId() == R.id.iv_product || v.getId() == R.id.order_ll) {//
                onCartAddListener.onCartAdd(5, position, bean, v);

            } else if (v.getId() == R.id.v_cart_bg) {

            } else if (v.getId() == R.id.iv_often_delete) {
                onCartAddListener.onCartAdd(0, position, bean, v);
            } else if (v.getId() == R.id.tv_home_often_compare) {
                onCartAddListener.onCartAdd(7, position, bean, v);
            } else if (v.getId() == R.id.rl_msg) {
                onCartAddListener.onCartAdd(10, position, bean, v);
            } else if (v.getId() == R.id.ll_offer) {
/*                SharedPreferences sp = FileUtil.getSharedPreferences();
                if (!sp.getBoolean("hadOfferAsk", false)) {
                    SharedPreferences.Editor editor = sp.edit();
                    editor.putBoolean("hadOfferAsk", true);
                    editor.commit();
                    context.initFirst(v);
                    return;
                }*/
                if (context.getUser().getAccess_token() == null) {
                    Intent intent = new Intent(context.getAppActivity(), LoginActivity.class);
                    intent.putExtra("relogin", true);
                    context.startActivityForResult(intent, 9999);
                    return;
                }

/*                Log.e("getCertStatus",""+context.getUser().getCertStatus());
                if(context.getUser().getCertStatus()==0||context.getUser().getCertStatus()==3) {
                    context.showNameSure();
                    return;
                }*/

                if (!bean.isAcceptOrders()) {
                    T.toast("暂不接单");
                    return;
                }

                if (bean.getOfferProductDto().getStatus() == 3 || bean.getOfferProductDto().getStatus() == 4 || bean.getOfferProductDto().getStatus() == 5)
                    onCartAddListener.onCartAdd(20, position, bean, v);//再次问价
                else
                    T.toast("要货" + bean.getOfferProductDto().getQuantity() + bean.getChargeUnit());
            }/*else if(v.getId() == R.id.gif_1 ||v.getId() == R.id.gif_2 ||v.getId() == R.id.gif_3 ||v.getId() == R.id.gif_4){
                if (!bean.isAcceptOrders()) {
                    T.toast("暂不接单");
                    return;
                }
                if(bean.getOfferProductDto()!=null&&(bean.getOfferProductDto().getStatus()==1||bean.getOfferProductDto().getStatus()==2))
                     T.toast("要货"+bean.getOfferProductDto().getQuantity()+bean.getUnit());
            }*/

        }
    }


    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(
            @NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.include_home_often_offer, parent, false);
        resources = view.getResources();
        drawableSelect = resources.getDrawable(R.drawable.btn_home_offer_top_select);
        drawableUnSelect = resources.getDrawable(R.drawable.btn_home_offer_top_unselect);
        return new ViewHolder(view);
    }


    @Override
    protected void onBindViewHolder(@NonNull ViewHolder vh, @NonNull HomeGoodsOften.ContentBean bean) {
        initView(vh, bean);
    }

    void initView(@NonNull ViewHolder vh, @NonNull HomeGoodsOften.ContentBean bean) {
        //vh.ll_offer.setVisibility(View.GONE);
        vh.ll_top.setVisibility(View.GONE);
        if (bean.isNumOne()) {
            vh.v_line_top.setVisibility(View.VISIBLE);
        }else {
            vh.v_line_top.setVisibility(View.GONE);
        }
        if (bean.isNumLast()) {

        }else {

        }
        //vh.ll_offer.setVisibility(View.VISIBLE);
        initOftenView(vh, bean);
        vh.ll_often.setVisibility(View.VISIBLE);
        return;
    }

    public void showCartAddView(ViewHolder vh, HomeGoodsOften.ContentBean bean) {
        boolean isShow;// = bean.isAcceptOrders()

        if ("".equals(bean.getGoodsCount())) {
            isShow = false;
        } else {
            if (bean.isAcceptOrders()) {
                isShow = true;
            } else {
                isShow = false;
            }
        }

        if (isShow) {
            vh.ivCountAdd.setVisibility(View.VISIBLE);
            vh.ivCountRemove.setVisibility(View.VISIBLE);
            vh.tvCountAdd.setVisibility(View.VISIBLE);
            vh.countAddUnderlineLayout.setVisibility(View.VISIBLE);
            vh.tvChargeNumber.setVisibility(View.VISIBLE);

            vh.ivAdd.setVisibility(View.GONE);

            //if (dcFlag) {
            if (bean.isStoreNeedBind()) {
                vh.rlMsg.setVisibility(View.VISIBLE);
                vh.vFlag.setVisibility(View.VISIBLE);
            } else {
                vh.rlMsg.setVisibility(View.GONE);
                vh.vFlag.setVisibility(View.GONE);
            }

        } else {
            vh.ivCountAdd.setVisibility(View.VISIBLE);
            vh.ivCountRemove.setVisibility(View.GONE);
            vh.tvCountAdd.setVisibility(View.GONE);
            vh.countAddUnderlineLayout.setVisibility(View.GONE);
            vh.tvChargeNumber.setVisibility(View.GONE);
            vh.vFlag.setVisibility(View.GONE);
            vh.ivAdd.setVisibility(View.GONE);

            vh.rlMsg.setVisibility(View.GONE);
            vh.vFlag.setVisibility(View.GONE);
        }
    }

/*

    void initState(@NonNull ViewHolder vh, @NonNull HomeGoodsOften.ContentBean beanParent) {
        vh.gif_1.setVisibility(View.GONE);
        vh.gif_2.setVisibility(View.GONE);
        vh.gif_3.setVisibility(View.GONE);
        vh.gif_4.setVisibility(View.GONE);
        vh.tv_offer_time_remind.setVisibility(View.GONE);

        OfferMyList bean = beanParent.getOfferProductDto();
        if(bean == null){
            bean = new OfferMyList();
            bean.setStatus(5);
            bean.setOfferStatusCopy("嫌贵？去问价");
            beanParent.setOfferProductDto(bean);
            vh.tv_offer_time_remind.setVisibility(View.GONE);
        }

        switch (bean.getStatus()) {

            //1报价中 2已报价 3放弃报价 4放弃问价 5报价失效
            case 1://绿色动图，灰色倒计时 努力报价中
                vh.tv_offer_time_remind.setVisibility(View.VISIBLE);

                vh.gif_1.setVisibility(View.VISIBLE);
                GifDrawable gifDrawable = (GifDrawable)vh.gif_1.getDrawable();
                gifDrawable.start();
                vh.tv_price_old.setTextColor(colors[0]);
                vh.tv_price_old.setPaintFlags(vh.tv_price_old.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
                vh.tv_offer_price.setVisibility(View.GONE);
                vh.tv_offer_hint.setVisibility(View.VISIBLE);
                vh.tv_offer_hint.setTextColor(colors[2]);
                vh.tv_offer_hint.setText(bean.getOfferStatusCopy());
                String buyTime = bean.getOfferBuyRemindTime();
                vh.tv_offer_time_remind.setText(bean.getOfferBuyRemindTime());
                if(buyTime.endsWith("5:00")||buyTime.endsWith("0:00")){
                    freshItemListener.freshItem(0,0,beanParent,null);
                }
                if("00:00".endsWith(buyTime)){
                    bean.setStatus(3);// TODO: 2018/7/9
                    bean.setOfferStatusCopy("忙碌，过会问");
                }
                break;
            case 2://5分钟内部红动图，红色倒计时；充裕红圈动图，灰色倒计时 新价格 老价格变黑横线
                vh.tv_offer_time_remind.setVisibility(View.VISIBLE);

                vh.tv_price_old.setTextColor(colors[1]);
                vh.tv_price_old.setPaintFlags(vh.tv_offer_price.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
                vh.tv_offer_price.setVisibility(View.VISIBLE);
                vh.tv_offer_hint.setVisibility(View.GONE);
                String sellTime = bean.getOfferSellRemindTime();
                vh.tv_offer_price.setText(bean.getNowPrice());
                vh.tv_offer_time_remind.setText(bean.getOfferSellRemindTime());
                if (bean.isLastBuyFiveFlag()) {
                    vh.gif_3.setVisibility(View.VISIBLE);
                    GifDrawable gifDrawable3 = (GifDrawable)vh.gif_3.getDrawable();
                    gifDrawable3.start();
                    vh.tv_offer_time_remind.setTextColor(colors[0]);
                } else {
                    vh.gif_2.setVisibility(View.VISIBLE);
                    GifDrawable gifDrawable2 = (GifDrawable)vh.gif_2.getDrawable();
                    gifDrawable2.start();
                    vh.tv_offer_time_remind.setTextColor(colors[1]);
                }
                if("00:00".endsWith(sellTime)){
                    bean.setOfferStatusCopy("嫌贵？去问价");
                    bean.setStatus(5);
                    vh.tv_offer_time_remind.setVisibility(View.GONE);
                }
                          */
    /*todo:倒计时 倒计时分两种 5分钟内红色*//*

                break;
            case 3://绿色静图 00:00  忙碌，过会问
                vh.tv_offer_time_remind.setVisibility(View.VISIBLE);
                vh.gif_4.setVisibility(View.VISIBLE);
                vh.tv_price_old.setTextColor(colors[0]);
                vh.tv_price_old.setPaintFlags(vh.tv_price_old.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
                vh.tv_offer_price.setVisibility(View.GONE);
                vh.tv_offer_hint.setText(bean.getOfferStatusCopy());
                vh.tv_offer_hint.setTextColor(colors[2]);
                vh.tv_offer_hint.setVisibility(View.VISIBLE);
                vh.tv_offer_time_remind.setText("00:00");
                break;
            case 4://绿色静图 00:00 可能没有该类型
                vh.tv_offer_time_remind.setVisibility(View.VISIBLE);
                vh.gif_4.setVisibility(View.VISIBLE);
                vh.tv_price_old.setTextColor(colors[0]);
                vh.tv_price_old.setPaintFlags(vh.tv_price_old.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
                vh.tv_offer_price.setVisibility(View.GONE);
                vh.tv_offer_time_remind.setText("00:00");
                vh.tv_offer_hint.setTextColor(colors[3]);
                break;
            case 5://绿色静图 嫌贵？00:00 去问价
                vh.tv_offer_time_remind.setVisibility(View.GONE);
                vh.gif_4.setVisibility(View.VISIBLE);
                vh.tv_price_old.setTextColor(colors[0]);
                vh.tv_price_old.setPaintFlags(vh.tv_price_old.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
                vh.tv_offer_price.setVisibility(View.GONE);
                vh.tv_offer_hint.setText(bean.getOfferStatusCopy());
                vh.tv_offer_hint.setTextColor(colors[3]);
                vh.tv_offer_hint.setVisibility(View.VISIBLE);
                vh.tv_offer_time_remind.setText("00:00");
                break;
        }
    }
*/

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvTitle;
        TextView tvUnitPackage;
        TextView tvMarketName;
        ImageView iv;
        ImageView ivAdd;
        ImageView ivCountAdd;
        ImageView ivCountRemove;
        TextView tvCountAdd;
        TextView tvChargeNumber;
        TextView countAddUnderlineTv;
        LinearLayout countAddUnderlineLayout;
        TextView tvPromotionStatus;
        ImageView ivCorner;
        ImageView ivCollect;
        View vCartBg;
        View vContent;
        View rlMsg;
        TextView tvMsg;
        View vFlag;
        View vArrow;

        View iv_often_delete, ll_often;//ll_offer,

        TextView tv_price_old, tv_offer_price, tv_home_often_store, tv_activity_promotion, tv_activity_second;
        TagCloudView tag;

        View ll_home_often_no, ll_package;


        View rl_detail;
        View ll_top, v_line_top, tv_home_often_compare;
        TextView rb_1, rb_2, rb_3;
/*
        TextView tv_offer_hint;

        GifImageView gif_1;
        GifImageView gif_2;
        GifImageView gif_3;
        ImageView gif_4;
        TextView tv_offer_time_remind;*/


        ViewHolder(@NonNull View view) {
            super(view);
/*
            gif_1 = view.findViewById(R.id.gif_1);
            gif_2 = view.findViewById(R.id.gif_2);
            gif_3 = view.findViewById(R.id.gif_3);
            gif_4 = view.findViewById(R.id.gif_4);
            tv_offer_time_remind = view.findViewById(R.id.tv_offer_time_remind);
*/

            ll_top = view.findViewById(R.id.ll_top);
            v_line_top = view.findViewById(R.id.v_line_top);
            tv_home_often_compare = view.findViewById(R.id.tv_home_often_compare);
            rb_1 = view.findViewById(R.id.rb_1);
            rb_2 = view.findViewById(R.id.rb_2);
            rb_3 = view.findViewById(R.id.rb_3);
            ll_often = view.findViewById(R.id.ll_often);
            //ll_offer = view.findViewById(R.id.ll_offer);
            iv = (ImageView) view.findViewById(R.id.iv_product);
            tvTitle = (TextView) view.findViewById(R.id.tv_product_title);
            tvUnitPackage = (TextView) view.findViewById(R.id.tv_unit_package);
            tvChargeNumber = (TextView) view.findViewById(R.id.tv_charge_number);
            tv_price_old = (TextView) view.findViewById(R.id.tv_price_old);
            tv_offer_price = (TextView) view.findViewById(R.id.tv_offer_price);
            //tv_offer_hint = view.findViewById(R.id.tv_offer_hint);
            iv_often_delete = view.findViewById(R.id.iv_often_delete);

            tv_home_often_store = (TextView) view.findViewById(R.id.tv_home_often_store);

            ivCountAdd = (ImageView) view.findViewById(R.id.iv_add_count);
            ivCountRemove = (ImageView) view.findViewById(R.id.iv_remove_count);
            vCartBg = view.findViewById(R.id.v_cart_bg);
            vContent = view.findViewById(R.id.order_ll);


            ivAdd = (ImageView) view.findViewById(R.id.iv_add);
            tvCountAdd = (TextView) view.findViewById(R.id.ed_price);
            countAddUnderlineLayout = view.findViewById(R.id.item_center_search_underline_layout);
            countAddUnderlineTv = view.findViewById(R.id.item_center_search_ed_price_underline);

            ivCorner = (ImageView) view.findViewById(R.id.iv_corner);
            tag = (TagCloudView) view.findViewById(R.id.ll_tags);


            rlMsg = view.findViewById(R.id.rl_msg);
            tvMsg = (TextView) view.findViewById(R.id.tv_msg);
            vFlag = view.findViewById(R.id.iv_msg);
            vArrow = view.findViewById(R.id.tv_msg_right);
            ivCollect = view.findViewById(R.id.iv_collect);

            vCartBg = view.findViewById(R.id.v_cart_bg);

            tv_activity_promotion = view.findViewById(R.id.tv_activity_promotion);
            tv_activity_second = view.findViewById(R.id.tv_activity_second);
            tvPromotionStatus = (TextView) view.findViewById(R.id.tv_promotion_status);

            ll_home_often_no = view.findViewById(R.id.ll_home_often_no);
            ll_package = view.findViewById(R.id.ll_package);

            rl_detail = view.findViewById(R.id.rl_detail);
        }
    }


    @SuppressLint("SetTextI18n")
    void initOftenView(@NonNull ViewHolder vh, @NonNull HomeGoodsOften.ContentBean bean) {
/*
        initState(vh,bean);
        vh.gif_1.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.gif_1.setTag(R.id.item_key_status, bean);
        vh.gif_1.setOnClickListener(this);
        vh.gif_2.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.gif_2.setTag(R.id.item_key_status, bean);
        vh.gif_2.setOnClickListener(this);
        vh.gif_3.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.gif_3.setTag(R.id.item_key_status, bean);
        vh.gif_3.setOnClickListener(this);
        vh.gif_4.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.gif_4.setTag(R.id.item_key_status, bean);
        vh.gif_4.setOnClickListener(this);

        vh.ll_offer.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.ll_offer.setTag(R.id.item_key_status, bean);
        vh.ll_offer.setOnClickListener(this);
*/


        vh.iv_often_delete.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.iv_often_delete.setTag(R.id.item_key_status, bean);
        vh.iv_often_delete.setOnClickListener(this);
        vh.iv_often_delete.setVisibility(View.VISIBLE);

        vh.vCartBg.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.vCartBg.setTag(R.id.item_key_status, bean);
        vh.vCartBg.setOnClickListener(this);
        vh.vContent.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.vContent.setTag(R.id.item_key_status, bean);
        vh.vContent.setOnClickListener(this);
        vh.tvTitle.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.tvTitle.setTag(R.id.item_key_status, bean);
        vh.tvTitle.setOnClickListener(this);

        vh.rlMsg.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.rlMsg.setTag(R.id.item_key_status, bean);
        vh.rlMsg.setOnClickListener(this);


        if (bean.isShowOfferThree()) {
            vh.tv_home_often_compare.setVisibility(View.GONE);
        } else {
            vh.tv_home_often_compare.setVisibility(View.GONE);
        }

        vh.tv_home_often_compare.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.tv_home_often_compare.setTag(R.id.item_key_status, bean);
        vh.tv_home_often_compare.setOnClickListener(this);

        ImageLoader.getInstance().displayImage(bean.getThumbnail(), vh.iv);
        //价格前后置
        if (bean.isPrePrice()) {
            vh.tv_price_old.setText("" + bean.getPrice());
        } else {
            vh.tv_price_old.setText("时价");
        }
        String pack = bean.getPack();
        if (pack == null || "".equals(pack)) {
            vh.tvUnitPackage.setVisibility(View.INVISIBLE);
        } else {
            vh.tvUnitPackage.setVisibility(View.VISIBLE);
        }
        if (bean.getSpecName() == null || bean.getSpecName().equals("默认")) {
            vh.tvUnitPackage.setText(pack);
        } else {
            vh.tvUnitPackage.setText(bean.getSpecName() + "(" + pack + ")");
        }

        vh.tvCountAdd.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.tvCountAdd.setTag(R.id.item_key_status, bean);
        vh.ivCountAdd.setTag(R.id.item_key_status, bean);
        vh.ivCountAdd.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.ivCountRemove.setTag(R.id.item_key_position, vh.getAdapterPosition());
        vh.ivCountRemove.setTag(R.id.item_key_status, bean);
        vh.ivCountRemove.setTag(R.id.item_key_position, vh.getAdapterPosition());

        vh.tvCountAdd.setOnClickListener(this);
        vh.ivCountAdd.setOnClickListener(this);
        vh.ivCountRemove.setOnClickListener(this);


        vh.tvTitle.setText(bean.getTitle());
        vh.tv_home_often_store.setText(bean.getStoreName());
/*
        String promotionType = bean.getPromotionItemType();

        if ("1".equals(promotionType)) {//1促销2秒杀
            vh.tv_activity_promotion.setVisibility(View.VISIBLE);
            vh.tv_activity_second.setVisibility(View.GONE);
        } else if ("2".equals(promotionType)) {//1促销2秒杀
            vh.tv_activity_promotion.setVisibility(View.GONE);
            vh.tv_activity_second.setVisibility(View.VISIBLE);
        } else {
            vh.tv_activity_promotion.setVisibility(View.GONE);
            vh.tv_activity_second.setVisibility(View.GONE);
        }*/
        String goodsCount = bean.getGoodsCount();
        vh.tvCountAdd.setText(goodsCount);
        vh.countAddUnderlineTv.setText(goodsCount);
        vh.tvChargeNumber.setText("已选" + goodsCount + bean.getChargeUnit());
        vh.tvMsg.setText(bean.getMsg());//留言
        ArrayList<HomeCommTag> tags = bean.getTags();
        if (tags != null && tags.size() > 0) {
            vh.tag.setVisibility(View.VISIBLE);
            vh.tag.setCommTags(tags);
        } else {
            vh.tag.setVisibility(View.GONE);
        }
        if (bean.isAcceptOrders() && !bean.isDisabled()) {
            vh.ivCountAdd.setImageResource(R.mipmap.price_add);
            //vh.ll_offer.setVisibility(View.VISIBLE);
        } else {
            vh.ivCountAdd.setImageResource(R.mipmap.price_grey);
            //vh.ll_offer.setVisibility(View.GONE);
            //vh.tv_offer_time_remind.setText("");
        }
        showCartAddView(vh, bean);
/*        if(bean.getOfferProductDto()!=null) {
            vh.ll_offer.setVisibility(View.VISIBLE);
            initState(vh, bean.getOfferProductDto());
        }else{
            vh.ll_offer.setVisibility(View.GONE);
        }*/

        if (bean.isDisabled()) {
            vh.tvTitle.setTextColor(Color.parseColor("#959595"));
            vh.tv_home_often_store.setTextColor(Color.parseColor("#959595"));
            vh.ll_home_often_no.setVisibility(View.VISIBLE);
            vh.ll_package.setVisibility(View.GONE);
        } else {
            vh.tvTitle.setTextColor(Color.parseColor("#313131"));
            vh.tv_home_often_store.setTextColor(Color.parseColor("#434343"));
            vh.ll_home_often_no.setVisibility(View.GONE);
            vh.ll_package.setVisibility(View.VISIBLE);
        }
    }


}
